import requests,re,codecs
class xiao():

    def down_file(self):#下载文件
        #输出二进制流---content  http://www.woniuxy.com/page/img/logo-500px.png
        res=requests.get(url='http://www.woniuxy.com/page/img/banner/allopen-home.jpg')
        with open('test.jpg','wb') as file:
            file.write(res.content)

    def sessi(self):#session--会话
        session=requests.session()#实例化session
        resq=session.post(url='http://localhost:8088/agileone/index.php/common/login',
                          data={"username":"admin","password":"admin","savelogin":"true"})
        print(resq.text)#打印文本方式的响应结果
        print(resq.content)#打印二进制流的响应结果
        resd=session.post(url='http://localhost:8088/agileone/index.php/notice/add',
                     data={'headline':'asdaasdasdas','content':'','scope':'1','expireddate':'2019-02-06'})
        print(resd.text)
        if re.match('successful',resq.text):##字符串匹配断言
            print('ok')

        if re.match('^\d{3}$',resd.text):#正则表达式断言
            print('ok')
        else:
            print('ko')
    def down_load(self):#####上传文件########
        session1=requests.session()#实例化session
        url='http://localhost:8088/agileone/index.php/attach/upload/refertype/defect/referid/4'#构建URL
        filename='D:/test_directory/testfile_1.txt'#上传文件
        uploadfile={"fileToUpload":("test.txt",codecs.open(filename,'r'))}#构建文件数据
        # uploadfile={"fileToUpload":("test.txt",open(filename,'r'))}#构建文件数据
        r=session1.post(url=url,files=uploadfile)#发送上传文件的请求
        print(r)

hello word   zhangxun456789